<template>
  <div class="department" id="department">
    <!-- 左侧部门管理 -->
    <div class="structureTree" v-if="treelength">
      <div class="structureTree_title">
        <div>组织机构</div>
        <div>
          <el-checkbox v-model="checked" @change="see()">查看下级</el-checkbox>
        </div>
      </div>
      <tree :treeData="treeData" :checkData="checkData" nodeKey="fCompanyid" @getTreeInfo="handleNodeClick"
        :defaultProps="defaultProps">
      </tree>
    </div>
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 机构名称 -->
      <el-breadcrumb :title="showName"></el-breadcrumb>
      <!-- 顶部导航栏 -->
      <div class="mechanism_nav">
        <!-- 左侧 -->
        <div class="mechanism_nav_left" style="width: 100%">
          <el-select class="selectBhz" v-model="getList.fUnittype" placeholder="巡查单位类型" @change="yj_searchForm(getList)"
            style="width: 160px">
            <el-option v-for="v in unittypeList" :key="v.label" :label="v.label" :value="v.value">
            </el-option>
          </el-select>

          <el-select class="selectBhz" v-model="getList.fStatus" placeholder="信息状态" @change="yj_searchForm(getList)"
            style="width: 160px">
            <el-option v-for="v in statusList" :key="v.label" :label="v.label" :value="v.value">
            </el-option>
          </el-select>
          <el-select class="selectBhz" v-model="getList.warningLevel" placeholder="预警状态" @change="yj_searchForm(getList)"
            style="width: 160px">
            <el-option v-for="v in warninglevelList" :key="v.label" :label="v.label" :value="v.value">
            </el-option>
          </el-select>
        </div>
        <!-- 顶部按钮 -->
        <div class="print">
          <div class="printTable">
            <el-button type="primary" icon="el-icon-refresh" size="small" @change="yj_searchForm(getList)">
            </el-button>
            <el-button type="primary" v-if="yj_view" icon="el-icon-search" size="small" @click="editText(fId)">查看
            </el-button>
          </div>
        </div>
      </div>
      <!-- 表格 -->
      <div class="text_table">
        <tableData :height="navigatepageNums > 1 ? 'calc(100% - 50px)' : '100%'" :config="table_config"
          :dataList="tableData" :loading="loading" @click-change="rowChange" @ClickOnLine="yj_viewForm"
          :page="getList.page" :pageSize="getList.pageSize" />
        <pagination v-if="navigatepageNums > 1" :info="queryCriteriaData" :treelength="treelength"
          :total="queryCriteriaData.total" :pageNum.sync="getList.page" :limit.sync="getList.pageSize"
          @pagination="yj_searchForm(getList)" />
      </div>
      <!--配合比通知单编号弹框 查看 -->
      <div class="Control-1 mechanism_dialogS closure">
        <el-dialog :title="dialogTitle" :modal-append-to-body="false" v-dialogDrag :visible.sync="dialogEditVisible"
          v-loading="loadingEditDialog" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)">
          <div class="dialogBody common" :style="{ height: '650px' }" style="overflow: hidden">
            <div style="overflow-y: auto; margin-bottom: 20px">
              <div class="baseTitle">质量巡查信息</div>
              <div class="publicForm" style="height: 285px">
                <publicForm ref="publicForm0" lableWidth="115px" :formObj="formObjShow" :formData="formData"
                  :timestamp="formData.fPatrolfileurl" :fileList="fHandlefileList">
                </publicForm>
              </div>

              <div class="baseTitle">巡查信息签收</div>
              <div class="publicForm" style="height: 80px">
                <publicForm ref="publicForm1" lableWidth="115px" :formObj="examineShow" :formData="formData">
                </publicForm>
              </div>
              <div class="baseTitle">整改信息回复</div>
              <div class="publicForm" style="height: 120px">
                <publicForm ref="publicForm1" lableWidth="115px" :formObj="rectificationShow" :formData="formData"
                  :timestamp="formData.fCompletionfile" :fileList="fCompletionfilelist">
                </publicForm>
              </div>
              <div style="height: 50px"></div>
            </div>
          </div>
        </el-dialog>
      </div>
    </div>
  </div>
</template>
  
<script>
import elBreadcrumb from "@/components/public/el-breadcrumb.vue";
import tree from "@/components/siteQualityPage/QualityGridManage/tree"; //左侧机构树
import TableData from "@/components/stationProductionPage/HntManage/el-tables"; //主页面列表
import Pagination from "@/components/public/el-pagination"; //主页面分页
import publicForm from "@/components/public/el-form.vue"; //弹框form
import formJs from "../regexDetail.js"; //新增弹框配置项
import {
  getUserCompanyTreeList, //左侧机构树接口
  getWorkProcessPatrol2PageLists, //主页面列表接口
  getWorkProcessPatrol2ByFid, //详情
} from "@/api/request.js";

export default {
  name: "patrolInformation",
  data() {
    return {
      name: "patrolInformation", //按钮配置页面代号
      yj_view: null, //查看

      // 分页
      navigatepageNums: null, //是否显示分页
      queryCriteriaData: {},
      // 分页

      // 列表
      getList: {
        fCompanyid: "", // 左侧选中组织机构id
        fQualitygridclass: "", // 上方查询条件质量网格
        fQualitygridtype: "", // 上方查询条件工程网格
        fUnittype: "", //巡查单位类型（集团公司，分子公司，项目公司，监理单位）
        fStatus: "", //信息状态---编辑中（可编辑，可下发），待签收（可签收），执行中（可整改编辑），已结束
        warningLevel: "", // 预警状态 一级预警（4，黄色），二级预警（2，橙色），三级预警（3，红色），
        page: 1, // 当前页码
        pageSize: 20, // 每页显示条数
        userId: "", // 查询待办或已办时传 列表页查询不传
        modelType: "2", // 0-待办 1-已办 传2 表示列表页查询
        sublevel: 1,
      },
      fId: null, //当前行数据fId
      row: {}, //选中行
      loading: false, //列表转载
      table_config: formJs.table_config,
      tableData: [], //表格列表数据列表
      unittypeList: [
        { label: "==单位类型==", value: "==单位类型==" },
        { label: "集团公司", value: "集团公司" },
        { label: "分子公司", value: "分子公司" },
        { label: "项目公司", value: "项目公司" },
        { label: "监理单位", value: "监理单位" },
      ], //巡查单位类型下拉框

      statusList: [
        { label: "==信息状态==", value: "==信息状态==" },
        { label: " 编辑中", value: " 编辑中" },
        { label: "待签收", value: "待签收" },
        { label: "执行中", value: "执行中" },
        { label: "已结束", value: "已结束" },
      ], //信息状态下拉框

      warninglevelList: [
        { label: "==预警状态==", value: "==预警状态==" },
        { label: "一级预警", value: "一级预警" },
        { label: "二级预警", value: "二级预警" },
        { label: "三级预警", value: "三级预警" },
      ], //预警状态下拉框

      // 列表

      // 弹框·
      timeYMD: null, //当前日期
      dialogTitle: "",
      loadingEditDialog: false, //弹框loading
      dialogEditVisible: false, //新增弹框是否显示
      formObjShow: formJs.formObjLook, //质量巡查信息
      examineShow: formJs.examineLook, //巡查信息签收
      rectificationShow: formJs.rectificationLook, //整改信息回复

      formData: formJs.formData,
      fHandlefileList: [], //上传文件
      fCompletionfilelist: [], //回复文件
      // 弹框

      // 机构树
      highlightBd: true, //左侧机构树停留背景色
      treelength: false, //左侧树显示隐藏
      checked: true, //查看下级按钮
      showName: "未选择公司",
      companyTree: "", //所有数据
      treeData: [], //左侧树状图数据
      defaultProps: {
        children: "children",
        label: "fShortname",
      },
      treeText: {
        companyId: null,
        userId: null,
      },
      checkData: [], //树状图默认选中id
      // 机构树
      userInfo: {}, //登录用户
    };
  },
  components: {
    elBreadcrumb,
    tree, //左侧组织机构数
    TableData, //主页面列表
    publicForm, //弹框表格
    Pagination, //分页
  },
  mounted() {
    this.userInfo = JSON.parse(sessionStorage.getItem("yjSmart-userInfo"));
    this.getList.userId = this.userInfo.userId

    // if (JSON.parse(sessionStorage.getItem("scene_getList"))) {
    //   var getData = JSON.parse(sessionStorage.getItem("scene_getList"));
    //   this.getList = {
    //     fCompanyid: getData.fCompanyid, // 左侧选中组织机构id
    //     fQualitygridclass: getData.fQualitygridclass, // 上方查询条件质量网格
    //     fQualitygridtype: getData.fQualitygridtype, // 上方查询条件工程网格
    //     fUnittype: getData.fUnittype, //巡查单位类型（集团公司，分子公司，项目公司，监理单位）
    //     fStatus: getData.fStatus, //信息状态---编辑中（可编辑，可下发），待签收（可签收），执行中（可整改编辑），已结束
    //     warningLevel: getData.warningLevel, // 预警状态 1：表示超期未结束 2：表示超期已结束
    //     page: 1, // 当前页码
    //     pageSize: 20, // 每页显示条数
    //     userId: getData.userId, // 查询待办或已办时传 列表页查询不传
    //     modelType: "2", // 0-待办 1-已办 传2 表示列表页查询
    //   };
    // }

    if (JSON.parse(sessionStorage.getItem("yjSmart-Quality_treeCheck"))) {
      var id = JSON.parse(sessionStorage.getItem("yjSmart-Quality_treeCheck"));
      this.checkData = [id.fCompanyid];
    }

    this.getTree();
    this.btnRole(this.name);
    this.table_config.operation.cols = [
      {
        prop: "fStatus",
        type: "primary",
        handleRow: this.handleRow,
      },
    ];
    this.table_config.operation["specialClass"] = function (rowData) {
      var color = null;
      if (rowData == "待签收") {
        color = "red !important";
      } else if (rowData == "执行中") {
        color = "orange !important";
      } else if (rowData == "已结束") {
        color = "green !important";
      } else {
        color = "#409eff !important";
      }
      return color;
    };
  },
  methods: {
    //查看下级
    see() {
      if (this.checked == true) {
        this.getList.sublevel = 1;
      } else {
        this.getList.sublevel = 0;
      }
      this.yj_searchForm(this.getList);
    },
    btnRole(name) {
      var btnList = [];
      var ModuleList = JSON.parse(sessionStorage.getItem("yjSmart-ModuleList"));
      if (ModuleList.length > 0) {
        ModuleList.map((item) => {
          if (item.fEncode == name) {
            btnList = item.modulebuttonList;
          }
        });
        var btnStr = [];
        btnList.map((item) => {
          btnStr.push(item.fEncode);
        });
        this.yj_view = btnStr.includes("yj_view");
      } else {
        this.yj_view = true;
      }
    },
    // 左侧树结构
    getTree() {
      this.treeText.companyId = this.userInfo.companyId;
      this.treeText.userId = this.userInfo.userId;
      getUserCompanyTreeList(this.treeText)
        .then((res) => {
          if (res.errcode == 0) {
            var companyTree = res.data.userCompanyTreeList;
            this.treeData = this.commonJs.tranListToTreeData(companyTree);

            if (this.treeData[0].children == undefined) {
              this.treelength = false; //左侧组织机构是否显示
            } else {
              this.treelength = true;
            }

            if (this.checkData[0]) {
              this.showName = JSON.parse(
                sessionStorage.getItem("yjSmart-Quality_treeCheck")
              ).fShortname;
              this.getList.fCompanyid = this.checkData[0];
            } else {
              this.showName = this.treeData[0].fShortname; //当前点击组织机构名称
              this.getList.fCompanyid = this.treeData[0].fCompanyid; //当前点击组织机构ID
              this.checkData[0] = this.treeData[0].fCompanyid;
            }
            console.log(this.getList);
            this.yj_searchForm(this.getList); // 调用主页面列表接口
            // 列表
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch(() => {
          return false;
        });
    },
    // 点击左侧机构树
    handleNodeClick(data) {
      this.showName = data.fShortname; //顶部显示机构名
      var sublevel = null;
      if (this.checked == true) {
        sublevel = 1;
      } else {
        sublevel = 0;
      }
      this.getList = {
        fCompanyid: data.fCompanyid, // 左侧选中组织机构id
        fQualitygridclass: "", // 上方查询条件质量网格
        fQualitygridtype: "", // 上方查询条件工程网格
        fUnittype: "", //巡查单位类型（集团公司，分子公司，项目公司，监理单位）
        fStatus: "", //信息状态---编辑中（可编辑，可下发），待签收（可签收），执行中（可整改编辑），已结束
        warningLevel: "", // 预警状态 1：表示超期未结束 2：表示超期已结束
        page: 1, // 当前页码
        pageSize: 20, // 每页显示条数
        userId: "", // 查询待办或已办时传 列表页查询不传
        modelType: "2", // 0-待办 1-已办 传2 表示列表页查询
        sublevel: sublevel,
      };
      this.yj_searchForm(this.getList);
    },

    // 获取列表数据
    yj_searchForm(id) {
      if (id.fUnittype == "==单位类型==") {
        id.fUnittype = "";
      }
      if (id.fStatus == "==信息状态==") {
        id.fStatus = "";
      }
      var warning = null;
      if (id.warningLevel == "一级预警") {
        warning = "4";
      } else if (id.warningLevel == "二级预警") {
        warning = "2";
      } else if (id.warningLevel == "三级预警") {
        warning = "3";
      } else {
        warning = "";
      }
      var data = {
        fCompanyid: id.fCompanyid, // 左侧选中组织机构id
        fQualitygridclass: id.fQualitygridclass, //上方查询条件质量网格
        fQualitygridtype: id.fQualitygridtype, // 上方查询条件工程网格
        fUnittype: id.fUnittype, //巡查单位类型（集团公司，分子公司，项目公司，监理单位）
        fStatus: id.fStatus, //信息状态---编辑中（可编辑，可下发），待签收（可签收），执行中（可整改编辑），已结束
        warningLevel: warning, // 预警状态 1：表示超期未结束 2：表示超期已结束
        page: id.page, // 当前页码
        pageSize: 20, // 每页显示条数
        userId: id.userId, // 查询待办或已办时传 列表页查询不传
        modelType: "2", // 0-待办 1-已办 传2 表示列表页查询
        sublevel: id.sublevel,
      };

      // window.sessionStorage.setItem("scene_getList", JSON.stringify(id));
      this.loading = true;
      getWorkProcessPatrol2PageLists(data)
        .then((res) => {
          if (res.errcode == 0) {
            var that = this;
            that.loading = false;
            that.tableData = res.data.pageInfo.list;
            that.queryCriteriaData = res.data.pageInfo;
            that.navigatepageNums =
              that.queryCriteriaData.navigatepageNums.length;
          } else {
            this.$message.error("列表", res.msg);
            this.loading = false;
          }
        })
        .catch(() => {
          this.loading = false;
        });
    },

    // 点击当前
    rowChange(val) {
      this.row = val;
      this.fId = val.fId;
    },

    // 点击查看
    yj_viewForm(row, label) {
      this.row = row;
      this.fId = row.fId;
      if (label == "巡查单位") {
        this.editText(row.fId);
      }
    },

    // 查看
    editText(id) {
      this.dialogTitle = "查看";
      if (id != "" && id != null) {
        this.loadingEditDialog = true; //弹框loading
        this.dialogEditVisible = true;
        // getQualityDutyStationByFid({ fId: id })
        getWorkProcessPatrol2ByFid({ fId: id })
          .then((res) => {
            if (res.errcode == 0) {
              this.loadingEditDialog = false; //弹框loading
              this.formData = res.data.yjQmpMsWorkprocessPatrol;
              this.fHandlefileList = res.data.fPatrolfileurllist;
              this.fCompletionfilelist = res.data.fCompletionfilelist;
            } else {
              this.$message.error("查看", res.msg);
              this.loadingEditDialog = false;
            }
          })
          .catch(() => {
            console.log("查看---详情接口报错");
            this.loadingEditDialog = false;
          });
      } else {
        return this.$message.error("请先选择需要查看的数据");
      }
    },
  },
};
</script>
  
<style scoped >
.printTables {
  background: #fff;
  display: flex;
  justify-content: end;
  padding: 5px;
  margin-top: 10px;
}

.dialogBody {
  padding: 3px 20px;
  height: 80%;
  overflow-y: auto;
}

.baseTitle {
  /* border: 1px solid #0c204d; */
  border-bottom: 1px solid #0c204d;
  height: 30px;
  line-height: 30px;
  position: relative;
  padding-left: 15px;
}

.baseTitle::after {
  display: block;
  content: "";
  height: 30px;
  width: 5px;
  position: absolute;
  left: 0;
  top: 0;
  background: #0c204d;
}

/* 弹框 */
.common /deep/.el-menu--horizontal>.el-menu-item.is-active {
  color: #409eff !important;
}

.publicForm .mouldForm /deep/ .el-form-item__content {
  margin-left: 120px !important;
}

/* 弹框 */
</style>
